﻿using CodeCity.SDK;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace CodeCity.UserManagement.Admin
{
    public class ExceptionFilter : IExceptionFilter
    {
        public void OnException(ExceptionContext context)
        {
            if (context.Exception is OperationException oe)
            {
                context.ExceptionHandled = true;
                context.Result = new BadRequestObjectResult(oe.Message);
                return;
            }
            if (context.Exception is NotOnlineException e)
            {
                context.ExceptionHandled = true;
                context.Result = new UnauthorizedResult();
                return;
            }
            Log.Error(context.Exception, "服务器出现异常");
        }
    }
}
